package com.szqhyxj.youxiangju.biz.partnerHome.shop;

import com.szqhyxj.youxiangju.biz.merchantHome.bean.PosCommodity;
import com.szqhyxj.youxiangju.sys.AbBasePresenter;
import com.szqhyxj.youxiangju.sys.BaseResult;

import java.util.List;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;

class PartnerShopPresenter extends AbBasePresenter implements PartnerShopContract.Presenter {

    private final PartnerShopContract.View view;

    public PartnerShopPresenter(PartnerShopContract.View view){
        this.view = view;
    }

    @Override
    public void init(){
        addDisposables(PartnerShopModel.queryCommodity()
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
        .subscribe(new Consumer<BaseResult<List<PosCommodity>>>(){
            @Override
            public void accept(BaseResult<List<PosCommodity>> listBaseResult) throws Exception{
                if(listBaseResult.businessLogicSuccess()){
                    view.showProductList(listBaseResult.getData());
                }else {
                     view.showToast(listBaseResult.getMessage());
                }
            }
        }, new Consumer<Throwable>(){
            @Override
            public void accept(Throwable throwable) throws Exception{
                view.showToast(throwable.getMessage());
            }
        }));
    }


}